/**
 * Created by zhangshun on 2018/8/13.
 */
module.exports ={
shareDL:function(app,options,flagIndex,tthis){
    var currentThis=this;
        if (options.enterType == 'undefined' || options.enterType == "" || options.enterType == null) {
            if(flagIndex==1){
                //首页标志
                currentThis.getLoginId(app,0,1,tthis);
            }
            if(decodeURIComponent(options.scene) && options.scene){
                var parentid = decodeURIComponent(options.scene).split("&");
                var parentMemberId="";
                for(var i=0;i<parentid.length;i++){
                    var s=parentid[i].split("=");
                    if(s[0]=="parentId"){
                        parentMemberId =s[1];
                    }
                }
                currentThis.getLoginId(app,parentMemberId,0,tthis);
            }
        }else {
            if (options.enterType == 0) {//分享转发进入
                var parentId=options.parentId;
                currentThis.getLoginId(app,parentId,options.enterType,tthis);
            }
        }
},
getLoginId:function(app,parentId,enterType,tthis){
    wx.login({
        success: function(res) {
            var memberLoginParamJson={
                code:res.code,
                enterType:enterType,
                parentId:parentId
            };
            wx.request({
                url: app.globalData.baseUrl + "/member/registerLogin",
                data: JSON.stringify(memberLoginParamJson),
                header: app.globalData.headerPost,
                method: 'POST',
                success: function (e) {
                    var memberId= e.data.data.memberId;
                    var openId= e.data.data.openId;
                    app.globalData.loginUserInfo.userInfo={
                        id: memberId,
                        memberId:memberId,
                        openId:openId
                    }
                    app.globalData.loginUserInfo["status"]= e.data.status;
                    wx.setStorageSync("loginUserInfo", app.globalData.loginUserInfo);
                    tthis.setData({
                        userInfo:wx.getStorageSync("loginUserInfo").userInfo
                    })
                },
                fail: function (e) {
                    wx.showToast({
                        title: '服务器开小差了，请稍后访问',
                        icon: 'none',
                        duration: 2000})
                }
            })
        }
    })
},

    getLogin:function(app,parentId,enterType,tthis,execuFlag){
        wx.login({
            success: function(res) {
                var memberLoginParamJson={
                    code:res.code,
                    enterType:enterType,
                    parentId:parentId
                };
                wx.request({
                    url: app.globalData.baseUrl + "/member/registerLogin",
                    data: JSON.stringify(memberLoginParamJson),
                    header: app.globalData.headerPost,
                    method: 'POST',
                    success: function (e) {
                        var memberId= e.data.data.memberId;
                        var openId= e.data.data.openId;
                        app.globalData.loginUserInfo.userInfo={
                            id: memberId,
                            memberId:memberId,
                            openId:openId
                        }
                        app.globalData.loginUserInfo["status"]= e.data.status;
                        wx.setStorageSync("loginUserInfo", app.globalData.loginUserInfo);
                        tthis.setData({
                            userInfo:wx.getStorageSync('loginUserInfo').userInfo==undefined?"":wx.getStorageSync('loginUserInfo').userInfo
                        })
                        if(execuFlag==1){
                            tthis.erweima();
                        }else if(execuFlag==3){
                            tthis.xiaofeijinAPI();
                        }

                    },
                    fail: function (e) {
                        wx.showToast({
                            title: '服务器开小差了，请稍后访问',
                            icon: 'none',
                            duration: 2000})
                    }
                })
            }
        })
    },
}